﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class ExperienceBLL
    {
        static int id = 0;
        HospitalDataContext DB = new HospitalDataContext();
        public List<Experience> Select(string StaffID)
        {
            return DB.Experiences.Where(e => e.StaffID == StaffID).ToList();
        }

        public string Insert(ExperienceDTO expDTO)
        {
            try
            {
                Experience exp = new Experience();
                exp.ExperienceID = (id++).ToString();
                exp.StaffID = expDTO.StaffID;
                exp.Position = expDTO.Position;
                exp.StartDate = expDTO.StartDate;
                exp.FinishDate = expDTO.FinishDate;
                exp.Organization = expDTO.Organization;

                DB.Experiences.InsertOnSubmit(exp);
                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public string Update(ExperienceDTO expDTO)
        {
            try
            {
                Experience exp = DB.Experiences.Where(e => e.ExperienceID == expDTO.ExperienceId).FirstOrDefault();
                exp.Position = expDTO.Position;
                exp.StartDate = expDTO.StartDate;
                exp.FinishDate = expDTO.FinishDate;
                exp.Organization = expDTO.Organization;

                DB.SubmitChanges();
                return "success";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
    }
}
